﻿<?php
$begintime = microtime(true);
require_once './lib.php';
header("Content-type:text/html;charset=utf-8");
$data = $_POST['data'];

$c_t = $data[0];
$c_r = $data[1];
$type = $data[2];
var_dump($c_t);
var_dump($c_r);
var_dump($type);


/**
 * @param $table 需要更新或是查询的表
 * @param $qishu 云端获取的开奖期数
 * @param $code  云端获取的开奖号码
 * @param int $parnum 根据参数选择对应的方法
 */
function insLotteryResult($table, $qishu, $code, $parnum = 5)
{
    $mysql = new DBAccess();
    if ($parnum == 5) {
        $sql = "select id from $table  WHERE qishu='$qishu'";
        $ball = explode(',', $code);
        if (!$mysql->getValue($sql)) {
            $ins_res = array(
                'qishu' => $qishu,
                'create_time' => date('Y-m-d H:i:s'),
                'datetime' => date('Y-m-d H:i:s'),
                "ball_1" => $ball[0],
                "ball_2" => $ball[1],
                "ball_3" => $ball[2],
                "ball_4" => $ball[3],
                "ball_5" => $ball[4],
            );
            $mysql->insertRow($table, $ins_res);
        }
    } elseif ($parnum == 3) {
        $sql = "select id from $table  WHERE qishu='$qishu'";
        $ball = explode(',', $code);
        if (!$mysql->getValue($sql)) {
            $ins_res = array(
                'qishu' => $qishu,
                'create_time' => date('Y-m-d H:i:s'),
                'datetime' => date('Y-m-d H:i:s'),
                "ball_1" => $ball[0],
                "ball_2" => $ball[1],
                "ball_3" => $ball[2],
            );
            $mysql->insertRow($table, $ins_res);
        }
    } elseif ($parnum == 8) {
        $sql = "select id from $table  WHERE qishu='$qishu'";
        $ball = explode(',', $code);
        if (!$mysql->getValue($sql)) {
            $ins_res = array(
                'qishu' => $qishu,
                'create_time' => date('Y-m-d H:i:s'),
                'datetime' => date('Y-m-d H:i:s'),
                "ball_1" => $ball[0],
                "ball_2" => $ball[1],
                "ball_3" => $ball[2],
                "ball_4" => $ball[3],
                "ball_5" => $ball[4],
                "ball_6" => $ball[5],
                "ball_7" => $ball[6],
                "ball_8" => $ball[7],
            );
            $mysql->insertRow($table, $ins_res);
        }
    } elseif ($parnum == 10) {
        $sql = "select id from $table  WHERE qishu='$qishu'";
        $ball = explode(',', $code);
        if (!$mysql->getValue($sql)) {
            $ins_res = array(
                'qishu' => $qishu,
                'create_time' => date('Y-m-d H:i:s'),
                'datetime' => date('Y-m-d H:i:s'),
                "ball_1" => $ball[0],
                "ball_2" => $ball[1],
                "ball_3" => $ball[2],
                "ball_4" => $ball[3],
                "ball_5" => $ball[4],
                "ball_6" => $ball[5],
                "ball_7" => $ball[6],
                "ball_8" => $ball[7],
                "ball_9" => $ball[8],
                "ball_10" => $ball[9],
            );
            $mysql->insertRow($table, $ins_res);
        }
    } elseif ($parnum == 20) {
        $sql = "select id from $table  WHERE qishu='$qishu'";
        $ball = explode(',', $code);
        if (!$mysql->getValue($sql)) {
            $ins_res = array(
                'qishu' => $qishu,
                'create_time' => date('Y-m-d H:i:s'),
                'datetime' => date('Y-m-d H:i:s'),
                "ball_1" => $ball[0],
                "ball_2" => $ball[1],
                "ball_3" => $ball[2],
                "ball_4" => $ball[3],
                "ball_5" => $ball[4],
                "ball_6" => $ball[5],
                "ball_7" => $ball[6],
                "ball_8" => $ball[7],
                "ball_9" => $ball[8],
                "ball_10" => $ball[9],
                "ball_11" => $ball[10],
                "ball_12" => $ball[11],
                "ball_13" => $ball[12],
                "ball_14" => $ball[13],
                "ball_15" => $ball[14],
                "ball_16" => $ball[15],
                "ball_17" => $ball[16],
                "ball_18" => $ball[17],
                "ball_19" => $ball[18],
                "ball_20" => $ball[19],
            );
            $mysql->insertRow($table, $ins_res);
        }
    }
}

/**
 * 循环将数据保存到数据库对应表中
 */


if ($type == 10002) {
    insLotteryResult("lottery_result_cq", $c_t, $c_r, 5);

} elseif ($type == 10001) {
    insLotteryResult("lottery_result_bjpk", $c_t, $c_r, 10);

} elseif ($type == 10006) {
    insLotteryResult("lottery_result_gd11", $c_t, $c_r, 5);

} elseif ($type == 10043) {

    insLotteryResult("lottery_result_p3", $c_t, $c_r, 3);

} elseif ($type == 10041) {
    insLotteryResult("lottery_result_d3", $c_t, $c_r, 3);

} elseif ($type == 10003) {
    insLotteryResult("lottery_result_tj", $c_t, $c_r, 5);

} elseif ($type == 10038) {
    insLotteryResult("lottery_result_gxsf", $c_t, $c_r, 5);

} elseif ($type == 10005) {
    insLotteryResult("lottery_result_gdsf", $c_t, $c_r, 8);

} elseif ($type == 10034) {
    insLotteryResult("lottery_result_tjsf", $c_t, $c_r, 8);

} elseif ($type == 10007) {
    insLotteryResult("lottery_result_t3", $c_t, $c_r, 3);

} elseif ($type == 10014) {

    insLotteryResult("lottery_result_bjkn", $c_t, $c_r, 20);
} elseif ($type == 10036) {

    insLotteryResult("lottery_result_jscq", $c_t, $c_r, 5);

} elseif ($type == 10037) {

    insLotteryResult("lottery_result_jssc", $c_t, $c_r, 10);

} elseif ($type == 10035) {

    insLotteryResult("lottery_result_jsft", $c_t, $c_r, 10);

}


$endtime = microtime(true);
$resultime = $endtime - $begintime;
echo "页面运行时间：$resultime";
